package jay.home.bet.web.struts;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jay.home.bet.domain.Event;
import jay.home.bet.misc.Util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class UpdateBanChangAction extends BaseAction {
	
	protected final Log log = LogFactory.getLog(getClass());
	
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception 
	{
		String dyHalfWin = request.getParameter("duyingHalf.win");
		String rqHalfHome = request.getParameter("rangqiuHalf.home");
		String dxHalfHome = request.getParameter("daxiaoHalf.home");
		String dyHalfLose = request.getParameter("duyingHalf.lose");
		String rqHalfRoad = request.getParameter("rangqiuHalf.road");
		String dxHalfRoad = request.getParameter("daxiaoHalf.road");
		String dyHalfDraw = request.getParameter("duyingHalf.draw");
		String id = request.getParameter("id");
		
		log.info("duyingHalf.win = " + dyHalfWin );
		log.info("rangqiuHalf.home = " + rqHalfHome );
		log.info("daxiaoHalf.home = " + dxHalfHome);
		log.info("duyingHalf.lose = " + dyHalfLose);
		log.info("rangqiuHalf.road = " + rqHalfRoad);
		log.info("daxiaoHalf.road = " + dxHalfRoad);
		log.info("duyingHalf.draw = " + dyHalfDraw);
		log.info("id = " + id);
		
		Event event = getOddsService().getEventByComp(id);
		
		event.getDuyingHalf().setWin(Util.toDouble(dyHalfWin));
		event.getRangqiuHalf().setHome(Util.toDouble(rqHalfHome));
		event.getDaxiaoHalf().setHome(Util.toDouble(dxHalfHome));
		event.getDuyingHalf().setLose(Util.toDouble(dyHalfLose));
		event.getRangqiuHalf().setRoad(Util.toDouble(rqHalfRoad));
		event.getDaxiaoHalf().setRoad(Util.toDouble(dxHalfRoad));
		event.getDuyingHalf().setDraw(Util.toDouble(dyHalfDraw));
		
		getOddsService().updateEventsByComp(event);
		Map map = getOddsService().getCounter(event.getId());
		
		
		request.setAttribute("event", event);
		request.setAttribute("map", map);
		return mapping.findForward("SUCCESS");
	}
}
